using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using GURUCORE.Framework.Core.Factory;

namespace GURUCORE.Framework.DataAccess.DataSource
{
	[FactoryClass("DataSources", "DataSource")]
	public class DataSourceFactory : FactoryBase
	{
		public const string GLOBAL_CACHE_KEY = "DataSourceFactory";

		public DataSourceFactory(string p_sFileName) : base(p_sFileName,typeof(DataSourceInfo))
		{
		}

		public string GetProvider(string p_sDataSource)
		{
            if (null == p_sDataSource)
			{
				p_sDataSource = this.GetFactoryAttribute("default");
			}
			DataSourceInfo oDSInfo = (DataSourceInfo)this.GetItem(p_sDataSource);
			return oDSInfo.Provider;
		}

		public string GetConnectionString(string p_sDataSource)
		{
            if (null == p_sDataSource)
			{
				p_sDataSource = this.GetFactoryAttribute("default");
			}
			DataSourceInfo oDSInfo = (DataSourceInfo)this.GetItem(p_sDataSource);
			string sConnStr = string.Empty;
			foreach (DictionaryEntry oEntry in oDSInfo.ConnectionInfo)
			{
				sConnStr += oEntry.Key + "=" + oEntry.Value + ";";
			}

			return sConnStr;
		}
	}
}
